#include "klippy/logging.h"
#include <iostream>
#include <mutex>

using namespace klippy;

namespace {
    std::mutex log_mutex;
}

Logger& Logger::get_instance() {
    static Logger instance;
    return instance;
}

Logger::Logger() : current_level_(INFO) {}

void Logger::set_level(LogLevel level) {
    std::lock_guard<std::mutex> lock(log_mutex);
    current_level_ = level;
}

void Logger::log(LogLevel level, const std::string& message) {
    if (level < current_level_) return;

    std::lock_guard<std::mutex> lock(log_mutex);
    
    const char* level_names[] = {"DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"};
    std::cerr << "[" << level_names[level] << "] " << message << std::endl;
}